<?php
	PhanQuyenAdmin();
	if(isset($_GET['id']) && isset($_GET['pin']))
	{
		$MaNguoiDung = trim($_GET['id']);
		$PIN        = trim($_GET['pin']);
		include_once '../classes/nguoidung_bs.php';
		include_once '../classes/nguoidungloai_bs.php';
		
		$NguoiDung = new nguoidung_bs();
		$NguoiDung->SetMaNguoiDung($MaNguoiDung);
		$DNguoiDung = $NguoiDung->LayDanhSach();
		
		if($DNguoiDung == null)
			header('Location: index.php?act=nguoidung');
		elseif(trim($DNguoiDung[0]['PIN']) == $PIN)
		{
?>
	<div class="FormCapNhat">
		<form action="index.php?act=nguoidung_capnhat_sub" method="POST">
			<div class="Title">
				Cập nhật thông tin người dùng - <?php echo $DNguoiDung[0]['MaNguoiDung']; ?>
			</div>
			
			<div class="Left">
				<table width="100%">
					<tr>
						<th colspan="2">Thông tin cá nhân</th>
					</tr>
					<tr>
						<td width="20%">Mã người dùng</td>
						<td><input name="MaNguoiDung" type="text" readonly="true" value="<?php echo $DNguoiDung[0]['MaNguoiDung']; ?>"/></td>
					</tr>
					<tr>
						<td>Họ tên</td>
						<td><input name="HoTen" style="font-weight:bold" type="text" value="<?php echo $DNguoiDung[0]['HoTen']; ?>"/></td>
					</tr>
					<tr>
						<td>Ngày sinh</td>
						<td><input type="text" name="NgaySinh" id="datepicker" value="<?php echo ConvertDate($DNguoiDung[0]['NgaySinh']); ?>"/></td>
					</tr>					
					<tr>
						<td>Địa chỉ</td>
						<td><input name="DiaChi" type="text" value="<?php echo $DNguoiDung[0]['DiaChi']; ?>"/></td>
					</tr>
					<tr>
						<td>Điện thoại</td>
						<td><input name="DienThoai" type="text" value="<?php echo $DNguoiDung[0]['DienThoai']; ?>"/></td>
					</tr>
					<tr>
						<td>Email</td>
						<td><input name="Email" type="text" value="<?php echo $DNguoiDung[0]['Email']; ?>"/></td>
					</tr>
					<tr>
						<td>Nhập lại email</td>
						<td><input name="XacNhanEmail" type="text" value="<?php echo $DNguoiDung[0]['Email']; ?>"/></td>
					</tr>
				</table>
			</div>
			<div class="Right">
				<table width="100%">
					<tr>
						<th colspan="2">CICT</th>
					</tr>
					<tr>
						<td width="35%">Chức vụ</td>
						<td>
							<?php
								include_once '../classes/chucvu_bs.php';
								$ChucVu = new chucvu_bs();
								$ChucVu->SetMaChucVu($DNguoiDung[0]['MaChucVu']);
								$DChucVu = $ChucVu->LayDanhSach();
								$MCV = $DChucVu == null ? '-' : $DChucVu[0]['MaChucVu'];
								
								$ChucVu = new chucvu_bs();
								$DChucVu = $ChucVu->LayDanhSach();
							?>
							<select name="ChucVu" id="">
								<option value="">---- Chọn chức vụ ----</option>
								<?php
									if($DChucVu != null)
									{
										for($i = 0; $i < count($DChucVu); $i++)
										{
											echo '<option ' . ($DChucVu[$i]['MaChucVu'] == $MCV ? 'selected="true"' : '') . ' value="' . $DChucVu[$i]['MaChucVu'] . '">' . $DChucVu[$i]['TenChucVu'] . '</option>';
										}
									}
								?>
							</select>
						</td>
					</tr>
					<tr>
						<td>Vai trò</td>
						<td>
							<input type="radio" id="radioNam" name="VaiTro" class="css-radio" <?php echo ($DNguoiDung[0]['MaLoaiNguoiDung'] == 'US1' ? 'checked="checked"' : '');?> value="US1"/>
							<label for="radioNam" class="css-labelRadio">Quản trị</label>
							<input type="radio" id="radioNu" name="VaiTro" class="css-radio" <?php echo ($DNguoiDung[0]['MaLoaiNguoiDung'] == 'US2' ? 'checked="checked"' : '');?> value="US2"/>
							<label for="radioNu" class="css-labelRadio">Giáo vụ</label>
						</td>
					</tr>
					
					
				</table>
				
			</div>
			
			<div class="Bottom">
				<table width="100%">
					<tr>
						<td width="50%" align="right"> <input type="submit" class="SubmitButton" onclick="return confirm('Bạn có chắc cập nhật?')" value="Cập nhật"/></td>
						<td width="50%"> <input type="reset" class="ResetButton" value="Đặt lại"/></td>
					</tr>
				</table>
			</div>
		</form>
	</div>
<?php
		}
		else
			header('Location: index.php?act=nguoidung');
	}
	else
	{
		header('Location: index.php?act=nguoidung');
	}